<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
var maxSubArray = function(nums) {
    var max = nums[0]
    for( var i = 0 ; i<nums.length ; i++ ){
        var sum = 0
        for( var j = i ; j<nums.length ; j++ ){
            sum += nums[j]
            if( sum>max ){
                max = sum
            }
        }
    }
    return max
};

var nums = [-2,1,-3,4,-1,2,1,-5,4]
console.log(maxSubArray(nums))
    </script>
</body>
</html>